package com.cy.pj.sys.controller;

import com.cy.pj.common.util.PageUtil;
import com.cy.pj.common.web.pojo.JsonResult;
import com.cy.pj.sys.pojo.CGBRoles;
import com.cy.pj.sys.service.CGBRolesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role/")
public class CGBRolesController {
    @Autowired
    private CGBRolesService cgbRolesService;

    @GetMapping("CheckRoles")
    public JsonResult doselectCheckRoles() {
        return new JsonResult(cgbRolesService.findCheckRoles());
    }

    @GetMapping("{id}")
    public JsonResult doFindById(@PathVariable Integer id) {
        return new JsonResult(cgbRolesService.findById(id));
    }

    @PostMapping
    public JsonResult doSaveRoles(@RequestBody CGBRoles cgbRoles) {
        cgbRolesService.saveRoles(cgbRoles);
        return new JsonResult("save ok");
    }

    @PutMapping
    public JsonResult doUpdateRoles(@RequestBody CGBRoles cgbRoles) {
        cgbRolesService.updateRoles(cgbRoles);
        return new JsonResult("update ok");
    }

    @GetMapping
    public JsonResult doFindRoles(CGBRoles cgbRoles) {
        return new JsonResult(PageUtil.startPage().doSelectPageInfo(() -> {
            cgbRolesService.findRoles(cgbRoles);
        }));
    }
}
